#include <iostream>
#include <string>
#include "../mqserver/exchange.hpp"
#include <gtest/gtest.h>
using namespace std;

rbmq::ExchangeManager::ptr emp;
// 全局的一个测试组件
class ExchangeTest : public testing::Environment { 
public :
    virtual void SetUp() override {
        emp = make_shared<rbmq::ExchangeManager>("./data/meta.db");
    }
    virtual void TearDown() override {
        //emp->clear();
    }

};

TEST(exchange_test, insert_test) {
    unordered_map<string, string> args; /*= { { "key1", "val1"}, {"key2", "val2" }, {"key3", "val3"}};*/
    emp->declareExchange("exchange1", mqNs::ExchangeType::DIRECT, true, false, args);
    emp->declareExchange("exchange2", mqNs::ExchangeType::DIRECT, true, false, args);
    emp->declareExchange("exchange3", mqNs::ExchangeType::DIRECT, true, false, args);
    emp->declareExchange("exchange4", mqNs::ExchangeType::DIRECT, true, false, args);
    ASSERT_EQ(emp->size(), 4);
}

// TEST(exchange_test, select_test) {
//     ASSERT_EQ(emp->exists("exchange1"), true);
//     ASSERT_EQ(emp->exists("exchange2"), true);
//     ASSERT_EQ(emp->exists("exchange3"), true);
//     ASSERT_EQ(emp->exists("exchange4"), false);
//     // rbmq::Exchange::ptr exp = emp->selectExchange("exchange1");
//     // ASSERT_NE(exp.get(), nullptr);
//     // ASSERT_EQ(exp->_name, "exchange1");
//     // ASSERT_EQ(exp->_type, mqNs::ExchangeType::DIRECT);
//     // ASSERT_EQ(exp->_durable, true);
//     // ASSERT_EQ(exp->_auto_delete, false);
//     //ASSERT_EQ(exp->get_args(), string("key1=val1&key2=val2&key3=val3"));
// }

// TEST(exchange_test, remove_test) {
//     emp->deleteExchange("exchange4");
//     rbmq::Exchange::ptr exp = emp->selectExchange("exchange4");
//     ASSERT_EQ(exp.get(), nullptr);
//     ASSERT_EQ(emp->exists("exchange4"), false);
// }


int main(int argc, char* args[]) {
    testing::InitGoogleTest(&argc, args);   
    testing::AddGlobalTestEnvironment(new ExchangeTest());
    RUN_ALL_TESTS();
    return 0;
}